<template>
    <div class="home-waterfall">
        <div class="title">
            <h2>{{ pageTitle }}</h2>
            <van-icon name="arrow" color="#999" />
        </div>
        <div class="list-box">
            <van-list
                v-model="loading"
                :finished="finished"
                finished-text="没有更多了"
                @load="onLoad"
            >
                <ul class="list-ul">
                    <li
                        class="list-li"
                        v-for="item in list"
                        :key="item.skuId"
                    >
                        <img :src="item.images" alt="" class="image">
                        <h6 class="title">{{ item.skuTitle }}</h6>
                        <div class="active" v-if="item.promotionList.length">
                            <div
                                class="active-item"
                                v-for="(cell, j) in item.promotionList"
                                :key="j"
                            >
                                <span v-if="cell.describe != ''">
                                    {{ cell.describe }}
                                </span>
                            </div>
                        </div>
                        <p class="price">
                            <strong>¥{{ item.discountPrice | toFix }}</strong>
                            <span>¥{{ item.originalPrice | toFix }}</span>
                        </p>
                        <div
                            class="tag"
                            v-if="item.promotionList.length"
                        >
                            <img :src="tagBgImg(item.promotionList[0].type)" alt="">
                            <span>{{ item.promotionList[0].tag }}</span>
                        </div>
                        <router-link
                            class="link"
                            tag="div"
                            :to="{name:'item', query: {id: item.skuId}}"
                        />
                    </li>
                </ul>
                <!-- <van-cell v-for="item in list" :key="item.skuId" :title="item.skuTitle" /> -->
            </van-list>
        </div>
    </div>
</template>

<script>
export default {
    name: 'homeWaterfall',
    data () {
        return {
            page: 0,
            pageSize: 20,
            pageTitle: null,
            list: [],
            loading: false,
            finished: false
        }
    },
    methods: {
        onLoad () {
            this.page += 1
            this.$http.getHomeWaterfallData(this.page, this.pageSize)
                .then(resp => {
                    // console.log(resp)
                    this.pageTitle = resp.info.titleConfig.title
                    this.list = this.list.concat(resp.skuInfo)
                    this.loading = false
                    if (this.page >= resp.pageTotal) {
                        this.finished = true
                    }
                })
        },
        tagBgImg (type) {
            if (type === 5) {
                return require('@/assets/img/home/tag-bg-5.png')
            } else if (type === 9) {
                return require('@/assets/img/home/tag-bg-9.png')
            } else if (type === 13) {
                return require('@/assets/img/home/tag-bg-13.png')
            } else if (type === -1) {
                return require('@/assets/img/home/tag-bg--1.png')
            } else {
                return require('@/assets/img/home/tag-bg--1.png')
            }
        }
    }
}
</script>

<style lang="scss">
.home-waterfall {
    > .title {
        padding: 0 25px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        h2 {
            font-size: 16px;
            color: #666;
            font-weight: bold;
        }
        p {
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: #999;
            font-size: 14px;
            font-weight: bold;
        }
    }
    .list-box {
        width: 100%;
        .list-ul {
            padding: 0 12px;
            width: 100%;
            box-sizing: border-box;
            display: flex;
            flex-wrap: wrap;
            overflow: hidden;
            .list-li {
                &:nth-of-type(even) {
                    margin-left: 2%;
                }
                width: 49%;
                background-color: #f9f9f9;
                border-radius: 8px;
                margin: 10px 0;
                padding: 10px;
                box-sizing: border-box;
                position: relative;
                .image {
                    width: 100%;
                    box-sizing: border-box;
                    padding-bottom: 10px;
                }
                .title {
                    font-size: 12px;
                    line-height: 16px;
                    color: #666;
                    font-weight: bold;
                    padding-bottom: 10px;
                }
                .active {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                    height: 40px;
                    .active-item {
                        span {
                            display: block;
                            padding: 5px;
                            background-color: #f8dbda;
                            border: 1px solid #e47c77;
                            border-radius: 5px;
                            color: #b9282b;
                            font-size: 8px;
                            font-weight: bold;
                            margin-left: 5px;
                        }
                    }
                }
                .price {
                    font-size: 12px;
                    font-weight: bold;
                    padding-bottom: 10px;
                    strong {
                        color: #c73734;
                    }
                    span {
                        color: #999;
                        text-decoration: line-through;
                        margin-left: 5px;
                    }
                }
                .tag {
                    width: 25px;
                    height: 25px;
                    position: absolute;
                    top: 10px;
                    right: 10px;
                    img {
                        position: absolute;
                        width: 100%;
                        height: 100%;
                        top: 0;
                        right: 0;
                        z-index: 1;
                    }
                    span {
                        display: block;
                        position: absolute;
                        width: 100%;
                        height: 100%;
                        top: 0;
                        left: 0;
                        z-index: 2;
                        font-size: 9px;
                        color: #fff;
                        text-align: center;
                        line-height: 25px;
                    }
                }
                .link {
                    width: 100%;
                    height: 100%;
                    position: absolute;
                    top: 0;
                    left: 0;
                }
            }
        }
    }
}
</style>
